/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skyproc;

import java.util.ArrayList;
import java.util.Objects;

/**
 * Form List Record
 * @author AliTheLord
 */
public class FLST extends MajorRecord {

    private static Type[] types = { Type.FLST };

    SubList<SubForm> LNAMs = new SubList<>(new SubForm(Type.LNAM));

    FLST() {
	super();
	subRecords.add(LNAMs);
    }

    /**
     *
     * @param modToOriginateFrom
     * @param edid EDID to give the new record.  Make sure it is unique.
     */
    public FLST (Mod modToOriginateFrom, String edid) {
	super(modToOriginateFrom, edid);
	subRecords.add(LNAMs);
    }

    @Override
    Type[] getTypes() {
	return types;
    }

    @Override
    Record getNew() {
	return new FLST();
    }
    
    /*
     * SkyBash Functions.
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FLST other = (FLST) obj;
        if (!Objects.equals(this.LNAMs, other.LNAMs)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 71 * hash + Objects.hashCode(this.LNAMs);
        return hash;
    }
    
    @Override
    public MajorRecord merge(MajorRecord no, MajorRecord bo) {
        super.merge(no, bo);
        FLST f = this;
        if (!(no == null && bo == null && (no instanceof FLST) && (bo instanceof FLST))) {
            final FLST nf = (FLST) no;
            final FLST bf = (FLST) bo;
            SubRecords sList = f.subRecords;
            SubRecords nsList = nf.subRecords;
            SubRecords bsList = bf.subRecords;
            for (SubRecord s : sList) {
                s.merge(nsList.get(s.type[0]), bsList.get(s.type[0]));
            }
        }
        return f;
    }

    /**
     *
     * @return List of all the FormIDs in the Form list.
     */
    public ArrayList<FormID> getFormIDEntries() {
	return SubList.subFormToPublic(LNAMs);
    }

    /**
     *
     * @param entry FormID to add to the list.
     */
    public void addFormEntry(FormID entry) {
	LNAMs.add(new SubForm(Type.LNAM, entry));
    }

    /**
     *
     * @param entry FormID to remove (if it exists).
     */
    public void removeFormEntry(FormID entry) {
	LNAMs.remove(new SubForm(Type.LNAM, entry));
    }

    /**
     *
     * @return
     */
    public int getSize() {
	return LNAMs.size();
    }

    /**
     *
     * @param entry
     * @param i
     */
    public void addFormEntryAtIndex(FormID entry, int i) {
	LNAMs.addAtIndex(new SubForm(Type.LNAM, entry), i);
    }
}
